package com.example.nacos.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.endpoint.event.RefreshEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
//@RefreshScope
public class ConfigurationController {
    private final ApplicationContext applicationContext;

    @Autowired
    public ConfigurationController(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    @GetMapping("/config")
    public String config(){
        return "env.get('test')=" +
                applicationContext.getEnvironment().getProperty("test", "unknown");
    }

    @GetMapping("/event")
    public String event(){
        applicationContext.publishEvent(new RefreshEvent(this, null, "just for test"));
        return "send RefreshEvent";
    }
}
